<template>
	<view class="container">
		<view class="text"><image src="/static/logo.png" class="logo"></image><view style="color: #999;font-size: 28rpx; margin-top:20rpx;">蝴蝶矩阵万名达人资源库</view></view>
		<button class="login" @click="Login"><image src="/static/wx.png"/><view>微信登陆</view></button>
		<view class="cancel" @click="Cancel">取消登陆</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				Code:'',
				Show:false
			};
		},
		onLoad() {
			console.log(uni.getStorageSync("Token"));
		},
		methods:{
			Login(){
				this.Util.Loading("请稍候...");
				uni.getUserProfile({
					desc: '微信登录',
					success: (user) => {//这里请求接口
						uni.login({
							provider: 'weixin',
							success: (res) => {
								this.Util.HideLoading();
								this.Code = res.code;  //微信临时登录凭证		
								var data = {};
								data.Act="Login_Xcx";
								data.Code = this.Code;
								this.Util.Post(data, json=>{
									this.Util.HideLoading();
									uni.setStorageSync("OpenID", json.Data.Info.OpenID);
									uni.setStorageSync("Token", json.Data.Info.Token);
									uni.setStorageSync("UserID", json.Data.Info.ID);
									uni.navigateBack({
									  delta:1
									})
									uni.$emit("Success");
								});
							},						
							fail: (err) => {
							}
						})		
					},
					fail: () => {
						uni.showToast({title:"微信登录授权失败",icon:"none"});
					}
				})
					
			},
			BindMobile(e){
				var data = {};
				data.Act="Find_XcxPhone";
				data.Iv = e.detail.iv;
				data.EncryptedData = e.detail.encryptedData;
				this.Util.Loading("请稍候...");
				this.Util.Post(data, json=>{
					uni.navigateBack({
					  delta:1
					})
					uni.$emit("Success");
				});
			},
			Cancel(){
				uni.setStorageSync("Cancel","true");
				uni.navigateBack({
					delta:1
				})
				setTimeout(item=>{
					uni.setStorageSync("Cancel","false");
				},3000);
			}
		}
	}
</script>

<style lang="scss">
	.container{padding-top:100rpx;}
	page{background-color: #fff;}
	.text{width:100%; height:240rpx;  float:left; text-align: center; font-size:26rpx;
		.logo{width: 200rpx;height: 200rpx;margin: 120rpx auto 0; border-radius: 40rpx;}
	}
	.login{width:86%; height: 100rpx; line-height: 100rpx; margin-top:200rpx;  color:#fff; margin-left:7%; float:left; background-color: #03c239; border-radius:50rpx;}
	.login image{float:left; margin-top:25rpx; width:60rpx; height:60rpx; margin-left:200rpx;}
	.login view{float:left; font-size:36rpx; padding-left:20rpx;}
	.cancel{width:100%; height: 200rpx; line-height: 200rpx; float:left; text-align: center; color:#a8a8a8;}
	.phonelogin{width:100%; height:100%;
		.meng{width:100%; height:100%; position:absolute; top:0rpx; left:0rpx; background-color: #000000; opacity: 0.5;}
		.phone{width:450rpx; height:300rpx; position: absolute; left:150rpx; top:calc(50vh - 150rpx); background-color: #ffffff; border-radius: 20rpx; 
			.title{width:100%; height:100rpx; padding-top:30rpx; text-align: center; font-size:38rpx; font-weight: bold;}
			.tip{width:100%; height:80rpx; text-align: center; font-size:32rpx; color:#999999; }
			.btn{width:100%; height:90rpx; text-align: center;
				button{width:80%; height: 90rpx; line-height: 90rpx; font-size:38rpx; color:#fff; margin-left:10%; float:left; background-color: #3598fc; border-radius:50rpx;}
			}
		}
		
	}
</style>
